package com.exde.wcsiapp.gps;

import android.util.Log;
import android.webkit.WebView;

public class SendHandlerMessageUtil {

    private static final String TAG = "sendHandlerMessageUtil";

    private static WebView webView;

    private static Gps gps;

    private static String function;

    private static String version;

    private static int result;

    public static void setWebView(WebView webView) {
        SendHandlerMessageUtil.webView = webView;
    }

    public static void setGps(Gps gps) {
        Log.d(TAG, "setGps: ");
        SendHandlerMessageUtil.gps = gps;
    }

    public static void setVersion(String version,int result){
        SendHandlerMessageUtil.version = version;
        SendHandlerMessageUtil.result = result;
    }

    public static void setFunction(String function) {
        Log.d(TAG, "setFunction: " + function);
        SendHandlerMessageUtil.function = function;
    }

    public static void setLocation(){
        // 通过Handler发送消息
        webView.post(new Runnable() {
            private double latitude = gps.getWgLat();
            private double longitude = gps.getWgLon();
            @Override
            public void run() {
                Log.d(TAG, "run: 执行方法="+function);
                // 注意调用的JS方法名要对应上
                webView.loadUrl("javascript:"+function+"('" + latitude + "','" + longitude + "')");
            }
        });
    }

    public static void setAndroidLocation(){
        // 通过Handler发送消息
        webView.post(new Runnable() {
            @Override
            public void run() {
                // 注意调用的JS方法名要对应上
                webView.loadUrl("javascript: setAndroidLocation()");
            }
        });
    }

    public static void setThisAndroid(){
        // 通过Handler发送消息
        webView.post(new Runnable() {
            @Override
            public void run() {
                // 注意调用的JS方法名要对应上
                webView.loadUrl("javascript:thisAndroid()");
            }
        });
    }

    public static void setAboutInof(){
        // 通过Handler发送消息
        webView.post(new Runnable() {
            @Override
            public void run() {
                // 注意调用的JS方法名要对应上
                Log.d("getAbout", "version :" + version);
                webView.loadUrl("javascript:setAbout('"+version+"','"+result+"')");
            }
        });
    }
}
